package com.spirng.leetcode.day02;

public class ReverseList {
    //双指针
    public ListNode reverseList(ListNode head) {
       ListNode cur=head;
       ListNode pre=null;
       while (cur!=null){
           ListNode temp=cur.next;
           cur.next=pre;
           pre=cur;
           cur=temp;
       }
       return pre;
    }
    //递归实现链表翻转
    public ListNode reverseList1(ListNode head) {

     return reverse(null,head);
    }
    public ListNode reverse(ListNode pre,ListNode cur){
        if(cur==null) return pre;
        ListNode temp=cur.next;
        cur.next=pre;
        return reverse(cur,temp);
    }
}
